/*
===========================================================================
Copyright (C) 2005 Sarunas

This file is part of MyPIRC source code.

DisksDB source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

DisksDB source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with DisksDB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
using System;

namespace MyIRC
{
	/// <summary>
	/// This class represents channel topic.
	/// Contains topic text, nick, who seted it and date.
	/// Gives ablity to change topic by modifing property Topic
	/// </summary>
	public class Topic : BaseObject, ITopic
	{
		private Channel chan = null;
		private string topic = null;
		private string setBy = null;
		private DateTime date = DateTime.Now;

		public Topic(IrcClient server, Channel chan) : base(server)
		{
			this.chan = chan;
		}

		/// <summary>
		/// Sets and Gets channel Topic
		/// </summary>
		public string Text
		{
			get
			{
				return (null == this.topic) ? "" : this.topic;
			}
			set
			{
				this.chan.SetTopic(value);
			}
		}

		/// <summary>
		/// The nick of the person who setted this topic
		/// </summary>
		public string Author
		{
			get
			{
				return (null == this.setBy) ? "" : this.setBy;
			}
		}

		/// <summary>
		/// When topic was set
		/// </summary>
		public System.DateTime Date
		{
			get
			{
				return this.date;
			}
		}

		public void SetTopic(string msg)
		{
			int pos = msg.IndexOf(':', 1);

			if (pos >= 0)
			{
				if (msg.Length == pos)
				{
					this.topic = null;
				} 
				else
				{
					this.topic = msg.Substring(pos + 1);
				}
			}
		}

		public void SetTopic(string topic, string who, DateTime date)
		{
			this.topic = topic;
			this.setBy = who;
			this.date = date;
		}

		public void SetDetails(string nick, DateTime date)
		{
			this.setBy = nick;
			this.date = date;
		}

		public void SetBy(string nick)
		{
			// TBD:
		}
	}
}
